<template>
  <!-- 添加或修改场内车辆管理对话框 -->
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="1000px"
    append-to-body
    :close-on-click-modal="false"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="98px" label-position="right"  class="flex-form" size="small">
          <el-form-item label="车辆编号" prop="veCustomsNo">
        <el-input v-model.trim="form.veCustomsNo" placeholder="请输入车辆编号" />
      </el-form-item>
    
          <el-form-item label="车牌号" prop="vehicleNo">
        <el-input v-model.trim="form.vehicleNo" placeholder="请输入车牌号" />
      </el-form-item>
    
          <el-form-item label="入场时间" prop="enterTime">
        <el-date-picker clearable size="small"
                        v-model.trim="form.enterTime"
                        type="date"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择入场时间">
        </el-date-picker>
      </el-form-item>
    
          <el-form-item label="入场重量" prop="enterWt">
        <el-input v-model.trim="form.enterWt" placeholder="请输入入场重量" />
      </el-form-item>
    
          <el-form-item label="场所代码" prop="fieldCode">
        <el-select v-model.trim="form.fieldCode" placeholder="请选择场所代码">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
    
          <el-form-item label="通道代码" prop="enterChannelCode">
        <el-select v-model.trim="form.enterChannelCode" placeholder="请选择通道代码">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
    
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="close">取 消</el-button>
      </div>
  </el-dialog>
</template>

<script>
import { getVehicleEnterRecord, addVehicleEnterRecord, updateVehicleEnterRecord } from "@/api/billsdecl/vehicleEnterRecord";
export default {
  name: "VehicleEnterRecord-addEdit",
  props: {
    dialogType: {
      type: String,
      default: "add",
    },
    rowData: {
      type: Object,
      default: () => {},
    },
    dict:{}
  },
  data() {
    return {
      // 弹出层
      dialogVisible: false,
      // 标题
      title: "新增",
      // 表单参数
      form: {
                                              id: null,
                                                            veCustomsNo: null,
                                                            vehicleNo: null,
                                                            enterTime: null,
                                                            enterWt: null,
                                                            fieldCode: null,
                                                            enterChannelCode: null,
                                                            createTime: null,
                                                            createBy: null
                        
      },
      // 场内车辆管理表格数据
      vehicleEnterRecordList: [],
      // 表单校验
      rules: {
        veCustomsNo: [
          { required: true, message: "车辆编号不能为空", trigger: "blur" }
        ],
        vehicleNo: [
          { required: true, message: "车牌号不能为空", trigger: "blur" }
        ],
        enterTime: [
          { required: true, message: "入场时间不能为空", trigger: "blur" }
        ],
        enterWt: [
          { required: true, message: "入场重量不能为空", trigger: "blur" }
        ],
        fieldCode: [
          { required: true, message: "场所代码不能为空", trigger: "change" }
        ],
        enterChannelCode: [
          { required: true, message: "通道代码不能为空", trigger: "change" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        createBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    open() {
      this.dialogVisible = true;
      this.$nextTick(() => {
        if (this.dialogType == "add") {
          this.title = "新增";
        } else if (this.dialogType == "edit") {
          this.title = "编辑";
          this.loadDetail();
        } else if (this.dialogType == "detail") {
          this.title = "详情";
          this.loadDetail();
        }
      });
    },
    close() {
      this.$refs["form"].resetFields();
      this.dialogVisible = false;
    },

    // 获取详情
    loadDetail() {
      const id = this.rowData.id;
      getVehicleEnterRecord(id).then((res) => {
        if (res.code == 200) {
          this.form = res.data;
                  }
      });
    },

    // 提交表单
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let params = {
            ...this.form,
          };
          if (this.dialogType == "add") {
            addVehicleEnterRecord(this.form).then(res => {
              if (res.code === 200) {
                this.$modal.msgSuccess("新增成功");
                this.close();
                this.$emit("handleQuery");
              }
            });
          } else {
            params.id = this.rowData.id;
            updateVehicleEnterRecord(this.form).then(res => {
              if (res.code === 200) {
                this.$modal.msgSuccess("修改成功");
                this.close();
                this.$emit("handleQuery");
              }
            });
          }
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
